<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        //创建类class
        class star {
            //constructor构造函数 在new时自动调用 自动返回
            constructor(uname, age) {
                this.uname = uname;
                this.age = age;
            }
            //类中添加方法
            sing(song) {
                console.log(this.uname+' '+song);
            }
        }
        //利用类创建对象new
        var ldh = new star('刘德华', 18);
        console.log(ldh);
        ldh.sing('冰雨');
        var zxy = new star('张学友', 20);
        console.log(zxy);
        zxy.sing('李香兰');

    </script>
</body>

</html>